package com.zdw.template.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zdw.template.dto.SeataDemoTwoDto;
import com.zdw.template.entity.SeataDemoTwoEntity;
import com.zdw.template.mapper.SeataDemoTwoMapper;
import com.zdw.template.service.SeataDemoTwoService;
import io.seata.core.context.RootContext;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 卓德文
 * @since 2022-11-22
 */
@Service
public class SeataDemoTwoServiceImpl extends ServiceImpl<SeataDemoTwoMapper, SeataDemoTwoEntity> implements SeataDemoTwoService {

    /**
     * 新增方法--测试seata分布式事务
     *
     * @param seataDemoTwoDto
     * @return
     */
    @Override
    @DS(value = "slave")
    //@GlobalTransactional(name = "seataTest",rollbackFor = Exception.class)
    public int insert(SeataDemoTwoDto seataDemoTwoDto) {
        System.out.println("xid:" + RootContext.getXID());
        SeataDemoTwoEntity seataDemoTwoEntity = BeanUtil.copyProperties(seataDemoTwoDto, SeataDemoTwoEntity.class);
        return this.baseMapper.insert(seataDemoTwoEntity);
    }
}
